<?php

namespace App\Model;

use App\Util\Traits\TimeHuman;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Model\Lost
 *
 * @mixin \Eloquent
 */
class Lost extends Model
{

    protected $table = 'lost';

    protected $guarded = [];

    protected $appends = ['human_time', 'code', 'update_human_time', 'thumbnail'];

    const PENDING = 0;
    const AUDITED = 1;
    const FINISH = 2;
    const DISAPPROVAL = 3;

    public function user()
    {
        return $this->hasOne(User::class, 'open_id', 'publisher');
    }

    public function getHumanTimeAttribute()
    {
        return Carbon::parse($this->created_at)->diffForHumans(Carbon::now());
    }

    public function getUpdateHumanTimeAttribute()
    {
        return Carbon::parse($this->updated_at)->diffForHumans(Carbon::now());
    }

    public function getCodeAttribute()
    {
        return \Crypt::encrypt($this->id);
    }

    public function getThumbnailAttribute()
    {
        return $this->cover . '?imageMogr2/gravity/Center/crop/1000x1000/thumbnail/200x200!';
    }
}
